//
//  UIButton+Extension.swift
//  我的微博
//
//  Created by ZhangChao on 15/9/9.
//  Copyright © 2015年 ZhangChao. All rights reserved.
//

import UIKit

extension UIButton{
    // 便利构造函数 设置标题,图像,字号,字体颜色
    convenience init(title: String , imageName: String , fontSize : CGFloat, textColor : UIColor){
        
        self.init()
        
        setTitle(title, forState: UIControlState.Normal)
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setTitleColor(textColor, forState: UIControlState.Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
    }
    
    // 便利构造函数 设置normal和highLight的图片
    convenience init(imageName : String){
        
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        sizeToFit()// 注意这句话必须加上,要不然不能正常显示
    }
    
}
